package com.ruoyi.web.controller.emergencyplan;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.pengjie.SnowflakeIdUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.emergencyplan.domain.EpEscapeRoute;
import com.ruoyi.emergencyplan.dto.EpEscapeRouteDto;
import com.ruoyi.emergencyplan.service.IEpEscapeRouteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 应急预案——避灾路线管理Controller
 * 
 * @author hcc
 * @date 2023-12-17
 */
@RestController
@RequestMapping("/emergencyplan/route")
public class EpEscapeRouteController extends BaseController
{
    @Autowired
    private IEpEscapeRouteService epEscapeRouteService;

    /**
     * 查询应急预案——避灾路线管理列表
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:route:list')")
    @GetMapping("/list")
    public TableDataInfo list(EpEscapeRoute epEscapeRoute)
    {
        startPage();
        List<EpEscapeRoute> list = epEscapeRouteService.selectEpEscapeRouteList(epEscapeRoute);
        return getDataTable(list);
    }

    /**
     * 导出应急预案——避灾路线管理列表
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:route:export')")
    @Log(title = "应急预案——避灾路线管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EpEscapeRoute epEscapeRoute)
    {
        List<EpEscapeRoute> list = epEscapeRouteService.selectEpEscapeRouteList(epEscapeRoute);
        ExcelUtil<EpEscapeRoute> util = new ExcelUtil<EpEscapeRoute>(EpEscapeRoute.class);
        util.exportExcel(response, list, "应急预案——避灾路线管理数据");
    }

    /**
     * 获取应急预案——避灾路线管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:route:query')")
    @GetMapping(value = "/{escapeRouteId}")
    public AjaxResult getInfo(@PathVariable("escapeRouteId") String escapeRouteId)
    {
        return success(epEscapeRouteService.selectEpEscapeRouteByEscapeRouteId(escapeRouteId));
    }

    /**
     * 新增应急预案——避灾路线管理
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:route:add')")
    @Log(title = "应急预案——避灾路线管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EpEscapeRoute epEscapeRoute)
    {
        epEscapeRoute.setEscapeRouteId(String.valueOf(new SnowflakeIdUtils(5,8).nextId()));
        return toAjax(epEscapeRouteService.insertEpEscapeRoute(epEscapeRoute));
    }

    /**
     * 修改应急预案——避灾路线管理
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:route:edit')")
    @Log(title = "应急预案——避灾路线管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EpEscapeRoute epEscapeRoute)
    {
        return toAjax(epEscapeRouteService.updateEpEscapeRoute(epEscapeRoute));
    }

    /**
     * 删除应急预案——避灾路线管理
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:route:remove')")
    @Log(title = "应急预案——避灾路线管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{escapeRouteIds}")
    public AjaxResult remove(@PathVariable String[] escapeRouteIds)
    {
        return toAjax(epEscapeRouteService.deleteEpEscapeRouteByEscapeRouteIds(escapeRouteIds));
    }
    /**
     * 查询应急预案——避灾路线管理列表
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:route:list')")
    @GetMapping("/getList")
    public TableDataInfo getList(EpEscapeRoute epEscapeRoute) {
        startPage();
        List<EpEscapeRouteDto> list = epEscapeRouteService.getEpEscapeRouteList(epEscapeRoute);
        return getDataTable(list);
    }
    /**
     * 查询应急预案——避灾路线管理列表
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:route:list')")
    @GetMapping("/getGisRouteInfo")
    public TableDataInfo getGisRouteInfo() {
        //TODO
        startPage();
        //List<EpEscapeRouteDto> list = epEscapeRouteService.getGisRouteInfo();
        //return getDataTable(list);
        return null;
    }
}
